import request from '@/utils/request'
import qs from 'qs'

export function add(data) {
  if (data.projectStartTime) {
    data.projectStartTime = data.projectStartTime + ' 00:00:00'
  }
  if (data.projectFinishTime) {
    data.projectFinishTime = data.projectFinishTime + ' 00:00:00'
  }
  if (data.invoiceTimestamp) {
    data.invoiceTimestamp = data.invoiceTimestamp + ' 00:00:00'
  }
  if (data.receivedTimestamp) {
    data.receivedTimestamp = data.receivedTimestamp + ' 00:00:00'
  }
  return request({
    url: '/api/project/add',
    method: 'post',
    data
  })
}

export function del(id) {
  return request({
    url: 'api/project/del/' + id,
    method: 'get'
  })
}

export function edit(data) {
  return request({
    url: '/api/project/update',
    method: 'post',
    data
  })
}

export function getReportBaseData(data) {
  return request({
    url: '/api/projectSummary/getBasicData' + '?' + qs.stringify(data, { indices: false }),
    method: 'get'
  })
}

export function getBarChartData(data) {
  return request({
    url: '/api/projectSummary/getProjectChart' + '?' + qs.stringify(data, { indices: false }),
    method: 'get'
  })
}

export function getMemberData(data) {
  return request({
    url: '/api/participate/getInfo' + '?' + qs.stringify(data, { indices: false }),
    method: 'get'
  })
}

export function getAddSaveData() {
  return request({
    url: '/api/project/getTempSaveObj',
    method: 'get'
  })
}

export function tempSave(data) {
  return request({
    url: '/api/project/tempSave',
    method: 'post',
    data
  })
}

export default { add, edit, del, getReportBaseData, getBarChartData, getMemberData, tempSave }
